package com.example.fw;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

public class WebDriverHelper extends HelperBase {

protected WebDriver driver;

public WebDriverHelper(ApplicationManager manager){
	super(manager);
	this.driver = manager.getDriver();
}

public boolean isElementPresent(By by) {
	try {
		driver.findElement(by);
		return true;
	} catch (NoSuchElementException e) {
		return false;
	}
}

protected void type(By locator, String text) {
	if (text != null) {
	driver.findElement(locator).clear();
	driver.findElement(locator).sendKeys(text);
	}
}
protected void click(By locator) {
	driver.findElement(locator).click();
}

protected WebElement findElement(By linkText) {
	try {
		return driver.findElement(linkText);
	} catch (Exception e){
		return null;
	}

}

protected void selectByText(By locator, String text) {
	if (text != null) {
	new Select(driver.findElement(locator)).selectByVisibleText(text);
	}	
}

protected void openUrl(String string) {
	driver.get(manager.getProperty("baseUrl") + string);
}

protected void openAbsoluteUrl(String string) {
	driver.get(string);
}

public void stop() {
	driver.quit();	
}

}
